package com.curry.cloud.controller;

import com.curry.cloud.rpc.FeignProvider;
import com.curry.cloud.rpc.FeignXaro;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequestMapping("/consumer")
@Slf4j
public class consumerController {

    @Autowired
    private FeignProvider feignProvider;
    @Autowired
    private FeignXaro feignXaro;

    @GetMapping("getValue/{num}")
    public Map getValue(@PathVariable Long num){

        Map map = feignProvider.getValue(num);
        System.out.println("服务调用 map = " + map);
        return map;
    }

/*    //超时降级演示
    @HystrixCommand(fallbackMethod = "payment_TimeoutHandler",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1500")//超过1.5秒就降级自己
    })*/


    @GetMapping("sleep")
    public String sleep(){
        String str = feignProvider.sleep();
        log.info("stop sleep log");
        System.out.println("stop sleep println");
        return str;
    }

    @GetMapping("feignXaro/{bucketName}")
    public void feignXaro(@PathVariable String bucketName){

        feignXaro.testFeignFallback(bucketName);
        System.out.println("服务调用");
    }

/*    //兜底方法，上面方法出问题,我来处理，返回一个出错信息
    public String payment_TimeoutHandler() {
        return "我是消费者80,对方支付系统繁忙请10秒后再试。或自己运行出错，请检查自己。";
    }*/




}
